<?
include_once 'lib/facebook.php';
include_once 'includes/config.php';
include_once 'includes/dbconnect.php';
include_once 'tableObjects/TblMember.php';
include_once 'includes/function.php';
$_SESSION['pid'] = 'instruction';

checkFbAuth();

if (SANDBOX_MODE == 0) {


    $isFan = $facebook->api(array(
        "method" => "pages.isFan",
        "page_id" => FACEBOOK_PAGE_ID,
        "uid" => $_SESSION['fb_id']
            ));
} else {
    $isFan = true;
}


$isFan = True;

if ($isFan === TRUE) {
    include_once 'includes/header.php';
    ?>
    <link type="text/css" href="includes/css/jquery.jscrollpane.css" rel="stylesheet" media="all" />
    <style type="text/css" id="page-css">
        /* Styles specific to this particular page */
        .scroll-pane
        {
            width: 100%;
            height: 570px;
            overflow: auto
        }
        .horizontal-only
        {
            height: auto;
            max-height: 200px;
        }
    </style>
    <script type="text/javascript" src="includes/js/jquery.mousewheel.js"></script>
    <script type="text/javascript" src="includes/js/jquery.jscrollpane.min.js"></script>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script type="text/javascript" src="includes/js/jquery.gchart.min.js"></script>


    <script language="javascript">
        function updateChart(question_id,data){
            alert(data);                                              
            drawChart(question_id, "10", "5");                                                   
        }
                                                                                    
                                                                                    
        function getChart(question_id)
        {		
            $.ajax({
                                                                                                        		
                type: "POST",
                url: 'chart.php',
                data: "question_id=" + question_id, 
                success: function(data) {
                    updateChart(question_id,data);                                      
                }
                                                                                                        	
            });
                                                                                                        				
        }

        function submitAnswer(answer,question_id)
        {                                                                            
            $.ajax({
                type: "POST",
                url: 'answer_submit.php',
                data: "question_id="+question_id+"&answer="+answer, 
                success: function(data) {
                    getChart(question_id);
                    //$('#divChart'+question_id).html(data);
                }
            });	 
        }
                                                                                                        	
                                                                                                  
    </script>
    <div id="divComment">

    </div>


    <table width="515" cellpadding="0" cellspacing="0" >
        <tr>
            <td height="50" bgcolor="#fec832" style="padding-left:20px">
                <img src="images/title_whatsyourtake.png">
            </td>
        </tr>
        <Tr>
            <td style="border:1px solid #f5f5f5;padding-left:20px" width="100%">
                <table width="100%">
                    <td height="570">
                        <img src="images/text_doesbankingmatter.png">
                    </td>
                    <Td width="230" style="background-color:#cccccc">
                        <div class="scroll-pane">
                            <?
                            $get = mysql_query("select * from tbl_question order by id asc") or die(mysql_error());
                            $no = 1;
                            while ($q = mysql_fetch_assoc($get)) {
                                $question_id = $q['id'];
                                $got_result = 0;
                                $get_yes = mysql_query("select count(*) as result from tbl_answer where answer='Y' and question_id='$question_id'");
                                $get_no = mysql_query("select count(*) as result from tbl_answer where answer='N' and question_id='$question_id'");

                                $total_yes = mysql_result($get_yes, 0, "result");
                                $total_no = mysql_result($get_no, 0, "result");
                                ?>

                                <div style="padding-bottom:2px">
                                    <table width="220"  cellpadding="0" cellspacing="0" style="background-color:#f1f1f1">
                                        <tr>
                                            <td style="vertical-align: top;padding-right: 10px" colspan="2" >
                                                <img src="images/btn_twitter.png" style="float:right;margin-right: 2px">                                        
                                                <img src="images/btn_facebook.png" style="float:right;margin-right: 2px">
                                            </td>
                                        </tr>
                                        <tr >
                                            <td style="vertical-align: middle;padding-left: 20px" height="65">
                                                <div id="divChart<?= $q['id'] ?>" style="width: 100px; height: 100px;">
                                                    No vote yet
                                                </div>

                                            </td>
                                            <td width="100" style="float:right;display: block;vertical-align: middle;padding-top:20px;padding-left: 20px">
                                                <a href="javascript:submitAnswer('Y',<?= $q['id'] ?>)"><img src="images/box_yes.jpg" style="float:left;margin-right: 4px" border="0"> Yes</a>
                                                <br>
                                                <a href="javascript:submitAnswer('N',<?= $q['id'] ?>)"><img src="images/box_no.jpg"  style="float:left;margin-right:4px" border="0"> No</a>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" style="vertical-align: top;padding-top:15px" >
                                                <table width="90%" align="center">
                                                    <Td style="vertical-align: top"><b><?= $no ?></b></td>
                                                    <td><?= $q['question'] ?></td>

                                                </table>

                                            </td>
                                        </tr>

                                    </table>
                                </div>
                                <?
                                if ($total_yes > 0 || $total_no > 0) {
                                    ?>

                                    <script>
                                        var data = [$.gchart.series('2004', [<?= $total_yes ?>,<?= $total_no ?>])]; 
                                        data[0].color= ['#f9be20', '#000000'];
                                        data[0].label= ['#f9be20', '#000000'];
                                                         
                                        $('#divChart<?= $q['id'] ?>').gchart
                                        (
                                        {
                                            type: 'pie', 
                                            series: data, 
                                            pieOrientation : 180,
                                            backgroundColor : 'transparent',
                                          
                                                        
                                        }); 
                                                 
                                                    
                                                                                                                                       
                                    </script>

                                <? } ?>
                                <? $no++;
                            } ?>

                        </div>
                        <script>
                            $(function()
                            {
                                $('.scroll-pane').jScrollPane({autoReinitialise: true});
                            });
                        </script>
                    </td>
                </table>
            </td>
        </tr>

    </table>
    <?
    include_once 'includes/footer.php';
} else {


    echo "<script type='text/javascript'>top.location.href = '" . FACEBOOK_PAGE_TAB_URL . "';</script>";

    /*
      <table id="Table_01" width="100%" border="0" cellpadding="0" cellspacing="0" style="background:url(images/bg_joininginstruction.png) right no-repeat">

      <tr>

      <td width="470" height="630" align="center" valign="middle">
      <br><br>
      <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {return;}
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
      fjs.parentNode.insertBefore(js, fjs);
      }(document, 'script', 'facebook-jssdk'));</script>

      <div class="fb-like-box" data-href="<?= FACEBOOK_PAGE_URL ?>" data-width="292" data-height="235" data-show-faces="true" data-stream="false" data-header="false" style="background-color:#ffffff">
      </div>
      <br>
      <br>
      <input type="button" value="CONTINUE" onclick="window.open('landing.php','_self')" class="button yellow">

      </td>

      </tr>
      </table>
     */
}
?>